import { useCallback, useEffect, useRef } from "react";
import styles from "./index.module.less";

interface IFrameProps {
    src: string
}

const IFrame: React.FC<IFrameProps> = ({ src }) => {
    const iframeRef = useRef(null as any);

    // const updateHeight = useCallback(() => {
    //     const iframe = iframeRef.current as HTMLIFrameElement;
    //     const height = iframe?.contentWindow?.document.documentElement.scrollHeight;
    //     if (height) {
    //         iframe.height = height + 'px';
    //     }
    //     setTimeout(updateHeight, 200);
    // }, [iframeRef]);

    // useEffect(() => {
    //     window.setTimeout(updateHeight, 200);
    // }, [updateHeight]);

    return <iframe title={src} src={src} seamless className={styles.iframe} ref={iframeRef}></iframe>
}

export default IFrame;